﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using AdslMonitorlibrary;
using System.Configuration;

namespace AdslMonitorService
{
    public partial class AdslMonitorService : ServiceBase
    {
        private System.Timers.Timer _timer;

        public AdslMonitorService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (AdslMonitor.SetupCategory())
            {
                this.Stop();
                return;
            }

            _timer = new System.Timers.Timer(double.Parse(ConfigurationManager.AppSettings["interval"]));
            _timer.AutoReset = true;
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
        }

        void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            AdslMonitor.Log();
        }

        protected override void OnStop()
        {
            _timer.Stop();
            AdslMonitor.ClearCounter();
        }
    }
}
